﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.PUBC;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord.Queries;
namespace Mang24k99.Business.PUBC
{
    public partial class BKtPubcItems
    {
        public static void Create(MKtPubcItems model)
        {
            model.IsValidate = 1;
            model.InputTime = DateTime.Now;
            model.ModifyTime = DateTime.Now;
            model.DeleteTime = DateTime.Now;
            model.Create();
        }
        public static void Update(MKtPubcItems model)
        {
            model.ModifyTime = DateTime.Now;
            model.Update();
        }
        public static void Delete(MKtPubcItems model)
        {
            //删除默认字段在ondelete中执行
            model.Delete();
        }

        public static IList<MKtPubcItems> FindAll()
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("IsValidate",1),
            };
            return MKtPubcItems.SelectAll(criteria);
        }

        public static MKtPubcItems Find(object ID)
        {
            return MKtPubcItems.SelectByPrimaryKey(ID);
        }
        public static MKtPubcItems FindOne()
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtPubcItems.SelectOne(criteria);
        }
        public static MKtPubcItems FindFirst()
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtPubcItems.SelectFirst(criteria);
        }

        public static IList<MKtPubcItems> FindALLByProperty(string property, object value)
        {
            return MKtPubcItems.SelectALLByProperty(property, value);
        }

        public static IList<MKtPubcItems> FindALLSliced(int firstResult, int maxResult)
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("IsValidate",1),
            };
            return MKtPubcItems.SelectALLSliced(firstResult, maxResult, criteria);
        }
        public static IList<MKtPubcItems> FindALLQuery(int firstResult, int maxResult)
        {
            string strHql = @"Select MKtPubcItems"
                          + " from"
                          + " MKtPubcItems MKtPubcItems, MKtPubcCyc MKtPubcCyc, MKtPubcProduct MKtPubcProduct"
                          + " where"
                          + " MKtPubcItems.IsValidate = 1"
                          + " and MKtPubcItems.MKtPubcCyc.CycNO = MKtPubcCyc.CycNO"
                          + " and MKtPubcItems.MKtPubcProduct.BoardNO = MKtPubcProduct.BoardNO"
                          ;
            SimpleQuery query = new SimpleQuery(typeof(MKtPubcItems), strHql);
            query.SetQueryRange(firstResult, maxResult);
            return MKtPubcItems.SelectAllQuery(query);
        }
        public static int Count()
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("IsValidate",1),
            };
            return MKtPubcItems.Counts(criteria);
        }
        public static bool Exists(object id)
        {
            return MKtPubcItems.Exist(id);
        }
        /// <summary>
        /// 根据调查表编号，周期编号，条目显示名称返回记录
        /// </summary>
        /// <param name="boardno"></param>
        /// <param name="cycno"></param>
        /// <param name="itemname"></param>
        /// <returns></returns>
        public static IList<MKtPubcItems> NameValidate(int boardno,int cycno,string itemname)
        {
            MKtPubcItems item = new MKtPubcItems();
            string where = " where item.MKtPubcProduct.BoardNO="+boardno;
            where+=" and item.MKtPubcCyc.CycNO="+cycno;
            where += " and item.ItemName='"+itemname+"'";
            return (IList<MKtPubcItems>)MKtPubcItems.SelectByWhere(where);
        }
        /// <summary>
        /// 根据调查表编号，周期编号，条目简称返回记录
        /// </summary>
        /// <param name="boardno"></param>
        /// <param name="cycno"></param>
        /// <param name="itemAlias"></param>
        /// <returns></returns>
        public static IList<MKtPubcItems>AliasValidate(int boardno,int cycno,string itemAlias)
        {
            string where = " where item.MKtPubcProduct.BoardNO=" + boardno;
            where += " and item.MKtPubcCyc.CycNO=" + cycno;
            where += " and item.ItemAlias='" + itemAlias + "'";
            return (IList<MKtPubcItems>)MKtPubcItems.SelectByWhere(where);
        }
        /// <summary>
        /// 根据调查表编号，周期编号返回条目
        /// </summary>
        /// <param name="boardno"></param>
        /// <param name="cycno"></param>
        /// <returns></returns>
        public static IList<MKtPubcItems> SelectItems(int boardno, int cycno)
        {
            string where = " where item.MKtPubcProduct.BoardNO=" + boardno;
            where += " and item.MKtPubcCyc.CycNO=" + cycno;
            where += " and item.IsValidate=1";
            return (IList<MKtPubcItems>)MKtPubcItems.SelectByWhere(where);
        }
    }
}
